/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.model.core;

import org.eclipse.emf.ecore.EClass;
import org.w3c.dom.Element;

import edu.pku.sei.gefcommon.descriptor.annotation.MethodProperty;
import edu.pku.sei.modeler.model.xml.XMLUtility;

/**
 * @author zl
 * @author xy
 *
 */
public class MetaDataType extends MetaClassifier {
	protected static final boolean SERIALIZABLE_DEFAULT = true;
	
	boolean serializableFlag = SERIALIZABLE_DEFAULT;
	@MethodProperty(
			id = "DATATYPE_IS_SERIALIZABLE",
			catalog = "Model",
			name = CorePackage.DATATYPE_SERIALIZABLEFLAG,
			setter = "setSerializable"
			)
			
	public boolean isSerializable(){
	    return serializableFlag;
	}

	public void setSerializable(boolean newSerializable){
	    boolean oldSerializable = serializableFlag;
	    serializableFlag = newSerializable;
	    firePropertyChange("serializableFlag", oldSerializable, newSerializable);
	}	
	
	public void serialize(Element root) {
		super.serialize(root);
		XMLUtility.xmlInstance.serializeAttribute(root, CorePackage.DATATYPE_SERIALIZABLEFLAG, serializableFlag);
	}
	
	public void deSerialize(Element root) {
		super.deSerialize(root);
		serializableFlag = XMLUtility.xmlInstance.deSerializeBoolean(root, CorePackage.DATATYPE_SERIALIZABLEFLAG);
	}
	
	@Override
	protected EClass eStaticClass() {
		return EMetaModelPackage.Literals.EMETA_DATA_TYPE;
	}
	
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case EMetaModelPackage.EMETA_DATA_TYPE__SERIALIZABLE_FLAG:
				return isSerializable() ? Boolean.TRUE : Boolean.FALSE;
		}
		return super.eGet(featureID, resolve, coreType);
	}
}
